package com.intellagric.controller.module.trace_record;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.RecordMachiningVo;
import com.intellagric.pojo.TraceRecordMachining;
import com.intellagric.service.traceability.trace_record.MachiningRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/1/13
 * @DESC： 加工记录表管理
 */
@Controller
public class MachiningRecordController {

    @Autowired
    private MachiningRecordService machiningRecordService;

    /**
     * 添加加工记录信息
     * @Param recordMachining
     * @return ResponseMessage
     */
    @RequestMapping("/record/machining/add")
    @ResponseBody
    public ResponseMessage add(TraceRecordMachining recordMachining) {
        recordMachining.setId(UUID.randomUUID().toString().replaceAll("-",""));
        recordMachining.setCreateDate(new Date());
        recordMachining.setUpdateDate(new Date());
        return machiningRecordService.addMachiningRecord(recordMachining);
    }

    /**
     * 删除加工记录信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/record/machining/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return machiningRecordService.deleteIMachiningRecord(id);
    }

    /**
     * 修改加工记录信息
     * @Param recordMachining
     * @return ResponseMessage
     */
    @RequestMapping("/record/machining/edit")
    @ResponseBody
    public ResponseMessage edit(TraceRecordMachining recordMachining) {
        return machiningRecordService.editMachiningRecord(recordMachining);
    }

    /**
     * 查询加工记录信息
     * @return TraceRecordMachining
     */
    @RequestMapping("/record/machining/{id}")
    @ResponseBody
    public TraceRecordMachining get(@PathVariable String id) {
        return machiningRecordService.getMachiningRecordById(id);
    }

    /**
     * 查询加工记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/machining/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return machiningRecordService.getMachiningRecordList();
    }

    /**
     * 分页查询加工记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/machining/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return machiningRecordService.getMachiningRecordPage(page, limit);
    }

    /**
     * 多条件分页查询加工记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/machining/query")
    @ResponseBody
    public LayuiDataGridResult getPageByVo(int page, int limit, RecordMachiningVo recordMachiningVo) {
        return machiningRecordService.getMachiningRecordPageByVo(page, limit,recordMachiningVo);
    }

}
